package com.nondo.dean.platform.controller.api.common;

import com.nondo.dean.common.cache.OssFileRedisTemplate;
import com.nondo.dean.common.thirdpart.ueditor.ActionEnter;
import com.nondo.dean.common.tool.AliyunOssTool;

import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@Controller
@RequestMapping("/api/thirtpart/ueditor")
public class UeditorEndpoint {

    private static final Logger logger = LoggerFactory.getLogger(UeditorEndpoint.class);

    @Autowired
    private AliyunOssTool aliyunOssTool;
    @Autowired
    private OssFileRedisTemplate ossFileRedisTemplate;

    @RequestMapping("/upload")
    public void upload(HttpServletRequest request, HttpServletResponse response) throws IOException {

        response.setCharacterEncoding("utf-8");
        try (PrintWriter out = response.getWriter()) {

            String json = new ActionEnter(request, response, "", aliyunOssTool, ossFileRedisTemplate).exec();
            out.append(json);

        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }


}
